package crp.core.resource.domain.models;

import crp.core.faculty.domain.models.FacultyEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ResourceWorkflowContextUtil {

    private static final String DEPARTMENT_ID = "departmentId";
    private static final String DEPARTMENT_NAME = "departmentName";
    private static final String COURSE_ID = "courseId";
    private static final String COURSE_NAME = "courseName";
    private static final String COURSE_CODE = "courseCode";
//    课程时长
//    private static final String COURSE_CODE = "courseCode";
    private static final String FACULTY_NAME = "facultyName";
    private static final String RESOURCE_NAME = "resourceName";
    private static final String RESOURCE_ID = "resourceId";


    public static String departmentIdQueryKey() {
        return String.format("context -> 'formAttributes' ->> '%s'", DEPARTMENT_ID);
    }

    public static String courseNameQueryKey() {
        return String.format("context -> 'formAttributes' ->> '%s'", COURSE_NAME);
    }

    public static String facultyNameQueryKey() {
        return String.format("context -> 'formAttributes' ->> '%s'", FACULTY_NAME);
    }

    public static Map<String, String> buildInstanceContext(CourseResourceEntity courseResource,
                                                           List<FacultyEntity> faculty) {
        Map<String, String> map = new HashMap<>(8);
        map.put(DEPARTMENT_ID, courseResource.getCourse().getAttributes().getOpenDepartment().getId());
        map.put(DEPARTMENT_NAME, courseResource.getCourse().getAttributes().getOpenDepartment().getName());
        map.put(COURSE_NAME, courseResource.getCourse().getName());
        map.put(COURSE_ID, courseResource.getCourse().getId());
        map.put(COURSE_CODE, courseResource.getCourse().getCode());
        map.put(FACULTY_NAME, faculty.stream().map(FacultyEntity::getName).collect(Collectors.joining(",")));
        map.put(RESOURCE_ID, courseResource.getResourceId());
        map.put(RESOURCE_NAME, courseResource.getResource().getName());
        return map;
    }
}
